package answer.service.Impl;

import answer.mapper.WeekMapper;
import answer.pojo.WeekTem;
import answer.service.WeekService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import commons.pojo.Special;
import commons.pojo.Week;
import commons.vo.LivegoodsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WeekServiceImpl implements WeekService {
    @Autowired
    private WeekMapper weekMapper;



    @Override
    public LivegoodsResult WeekSearch() {
        int y = 202301;
        Map<Object, Object> map = new HashMap<>();
        ArrayList<WeekTem> list = new ArrayList<>();
        List<Week> weeks = weekMapper.selectList(null);
        for (int week = 0 ; week < weeks.size();week++){
            if(weeks.get(week).getYear() == y){
                y++;
                list.add(new WeekTem(haha(weeks.get(week).getYear()),4));
            }
//            if(week == weeks.size()-1) list.set(list.size()-1,new WeekTem(haha(weeks.get(week).getYear()),weeks.get(week).getTime()));
        }
        map.put("每周答题",list);
        return LivegoodsResult.ok(map);
    }

    @Override
    public LivegoodsResult WeekAnswer(int name, int n) {
        QueryWrapper<Week> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("year",name);
        objectQueryWrapper.eq("time",n);
        List<Week> weeks = weekMapper.selectList(objectQueryWrapper);
//        List<Week> weeks = weekMapper.selectWeek(name, n);
        return LivegoodsResult.ok(weeks);
    }

    public String haha(int a){
        return a/100 + "年" + a%100 + "月" ;
    }
}